#include<bits/stdc++.h>
#define MAXN 100010
using namespace std;
int T,n,m,L,V,ans1,ans2,road[MAXN*10],pos[MAXN],d[MAXN],v[MAXN],a[MAXN];
int  main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    srand(time(0));
    cin>>T;
    while(T--){
        ans1=n=m=L=V=0;
        memset(d,0,sizeof(d));
        memset(v,0,sizeof(v));
        memset(a,0,sizeof(a));
        memset(pos,0,sizeof(pos));
        memset(road,0,sizeof(road));
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>pos[i];
            road[(int)pos[i]]=1;
        }
        for(int i=1;i<=n;i++){
            /*if(a[i]>0){
                if(v[i]>V&&d[i]<pos[m]){
                    ans1++;
                    continue;
                }
                double address=(V*V-v[i]*v[i])/(a[i]*2)+d[i];
                for(int j=d[i];j<=address;j++){
                    if(road[j]==1){
                        ans1++;
                        break;
                    }
                }
                //printf("%0.3lf\n",address);
            }
            if(a[i]<0){
                if(v[i]<=V){
                    continue;
                }
                double address=(V*V-v[i]*v[i])/(a[i]*2)+d[i];
                for(int j=d[i];j<=address;j++){
                    if(road[j]==1){
                        ans1++;
                        break;
                    }
                }
                //printf("%0.3lf\n",address);
            }*/
            if(a[i]==0&&v[i]>V){
                for(int j=d[i]+1;j<=L;j++){
                    if(road[j]==1){
                        ans1++;
                        break;
                    }
                }
            }
        }
        cout<<ans1<<endl;
        cout<<(rand()%100000)<<endl;
    }
    return 0;
}
